using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace Keyboard_N_Mouse
{
    public class KeyboardStatement
    {
	    KeyboardState keyboard_old,keyboard_now;

        public KeyboardStatement()
        {
            keyboard_old=keyboard_now=Keyboard.GetState();
        }

	    public void  Update()
	    {
		    keyboard_old = keyboard_now;
		    keyboard_now = Keyboard.GetState();
	    }

	    public bool HasKeyBeenPressed(Keys key)
	    {
		    if (keyboard_old[key] == KeyState.Up && keyboard_now[key] == KeyState.Down)
			    return true;
		    else
			    return false;
	    }

        public bool HasKeyBeenReleased(Keys key)
        {
            if (keyboard_old[key] == KeyState.Down && keyboard_now[key] == KeyState.Up)
                return true;
            else
                return false;
        }

	    public bool IsKeyDown(Keys key)
	    {
		    return keyboard_now.IsKeyDown(key);
	    }

	    public bool IsKeyUp(Keys key)
	    {
		    return keyboard_now.IsKeyUp(key);
	    }

	    public Keys[] GetPressedKeys(Keys key)
	    {
		    return keyboard_now.GetPressedKeys();
	    }
    }

    public class MouseStatement
    {
	    MouseState mouse_old, mouse_now;
	    public int ScrollWheelValue,Xnow,Ynow,Xbetween,Ybetween;
	    public ButtonState LeftButton, RigthButton, MiddleButton;

	    public MouseStatement()
	    {
		    mouse_old = mouse_now = Mouse.GetState();
	    }

	    public void Update(GraphicsDevice graphicsdevice)
	    {
		    mouse_old=mouse_now;
		    mouse_now=Mouse.GetState();
		    ScrollWheelValue = mouse_now.ScrollWheelValue;
            Xbetween = mouse_old.X - mouse_now.X;
            Ybetween = mouse_old.Y - mouse_now.Y;
            Xnow = mouse_now.X;
            Ynow = mouse_now.Y;
		    LeftButton = mouse_now.LeftButton;
		    RigthButton = mouse_now.RightButton;
		    MiddleButton = mouse_now.MiddleButton;
	    }

        // HBR - HasBeenPressed
	    public bool LeftButtonHBP()
	    {
		    if(mouse_old.LeftButton == ButtonState.Pressed && mouse_now.LeftButton == ButtonState.Released)
			    return true;
		    else 
			    return false;
	    }

	    public bool RigthButtonHBP()
	    {
		    if(mouse_old.RightButton == ButtonState.Pressed && mouse_now.RightButton == ButtonState.Released)
			    return true;
		    else 
			    return false;
	    }

	    public bool MiddleButtonHBP()
	    {
		    if(mouse_old.MiddleButton == ButtonState.Pressed && mouse_now.MiddleButton == ButtonState.Released)
			    return true;
		    else 
			    return false;
	    }

        // HBR - HasBeenReleased
        public bool LeftButtonHBR()
        {
            if (mouse_old.LeftButton == ButtonState.Released && mouse_now.LeftButton == ButtonState.Pressed)
                return true;
            else
                return false;
        }

        public bool RigthButtonHBR()
        {
            if (mouse_old.RightButton == ButtonState.Released && mouse_now.RightButton == ButtonState.Pressed)
                return true;
            else
                return false;
        }

        public bool MiddleButtonHBR()
        {
            if (mouse_old.MiddleButton == ButtonState.Released && mouse_now.MiddleButton == ButtonState.Pressed)
                return true;
            else
                return false;
        }
    }
}